home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / SOURCE / DACDMA.CPP < prev    next >
C/C++ Source or Header  |  1992-11-18  |  2KB  |  91 lines

  1. /* Output to SB DAC using DMA mode */
  2.  
  3. #include "stddefs.h"
  4.  
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <conio.h>
  8. #include <io.h>
  9. #include <alloc.h>
  10. #include <dos.h>
  11. #include <stdlib.h>
  12. #include <alloc.h>
  13. #include <fstream.h>
  14. #include "yaksound.h"
  15. #include "sb.h"
  16.  
  17. extern int optind;    /* index of which argument is next      */
  18. extern char *optarg;  /* pointer to argument of current option */
  19. extern int opterr;    /* allow error message  */
  20. extern "C" int getopt(int argc, char *argv[], char *optionS);
  21.  
  22. void main(int argc, char *argv[])
  23. {
  24.     FILE *f;
  25.     signed char far *raw, far *aligned;
  26.     long sample_len;
  27.     register int j, i;
  28.     unsigned sl, tmp, nr, sr=11000;
  29.     unsigned char tm;
  30.     unsigned long physical, aligned_physical;
  31.     char ch;
  32.     int stereo = 0, error = 0;
  33.  
  34.     while((ch = getopt(argc,argv,"sr:")) != EOF)
  35.     {
  36.     switch(ch)
  37.     {
  38.         case 's':
  39.         stereo = 1;
  40.         break;
  41.         case 'r':
  42.         sr = atoi(optarg);
  43.         break;
  44.         case '?':
  45.         error++;
  46.         break;
  47.     }
  48.     }
  49.     if(error || optind == argc)
  50.     {
  51.     puts("Usage: dacdma [-r rate] [-s] sample");
  52.     exit(1);
  53.     }
  54.  
  55.     if(Sb_Get_Params())
  56.     {
  57.         puts("BLASTER environment variable not set.");
  58.         exit(1);
  59.     }
  60.  
  61.     if(Sb_Init())
  62.     {
  63.     printf("Could not find Soundblaster!\n");
  64.     exit(1);
  65.     }
  66.     printf("Found Soundblaster at address %xh, IRQ %d, DMA %d.\n",
  67.     SbIOaddr,SbIRQ,SbDMAchan);
  68.  
  69.     printf("Sample rate = %d Hz\n",sr);
  70.     printf("Output is %s.\n",(stereo) ? "stereo" : "mono");
  71.     yakSample myYakSample(argv[optind]);
  72.     myYakSample.play(sr, stereo);
  73.     while(!kbhit() && !Sb_DMA_Complete())
  74.     ;
  75.     if(!Sb_DMA_Complete())
  76.     {
  77.     Sb_Halt_DMA();
  78.     getch();
  79.     }
  80.  
  81.     Sb_Voice(0);
  82.  
  83.     printf("Done.\n");
  84.  
  85.     Sb_DeInit_Voice_DMA();
  86.  
  87.     farfree(raw);
  88.  
  89.     exit(0);
  90. }
  91.